//数字转换
export const numLimit = (value) => {
  Number(value) > 999
    ? Number(value) >= 9999
      ? Math.floor((value / 1e4) * 100) / 100 + "w"
      : Math.floor((value / 1e3) * 100) / 100 + "k"
    : value;
};

// 获取appid
export const getAppId = () => {
  return uni.getAccountInfoSync().miniProgram.appId;
};

// 初始化处理表单规则
export const onReadyFormRule = (that, formRef, rules) => {
  that.$refs[formRef].setRules(that[rules]);
};

// 提示信息
export const showToast = (title, icon = "none", duration = 2000) => {
  uni.showToast({
    title,
    icon,
    duration,
  });
};

// 获取支付id
export const PAY_ID = "1846190237240123456";

/**
 * 功能:判断是否为空
 * @param v
 * @returns {boolean}
 */
export function isEmpty(v) {
  switch (typeof v) {
    case "undefined":
      return true;
    case "string":
      if (v.replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g, "").length == 0)
        return true;
      break;
    case "boolean":
      if (!v) return true;
      break;
    case "number":
      if (0 === v || isNaN(v)) return true;
      break;
    case "object":
      if (null === v || v.length === 0) return true;
      for (let i in v) {
        return false;
      }
      return true;
  }
  return false;
}
